package com.ruoyi.web.controller.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.system.service.ISysConfigService;

/**
 *
 * 
 * @author ruoyi
 */
@Api(value = "注册验证",tags = "注册验证")
@RestController
public class SysRegisterController extends BaseController
{
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;

    @ApiOperation("手机号注册")
    @PostMapping("/register")
    @ApiImplicitParams({  @ApiImplicitParam(name = "phone",value = "手机号", required = true)})
    public AjaxResult register(@RequestBody RegisterBody user)
    {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }


    @ApiOperation("判断手机号是否注册")
    @PostMapping("/isRegister")
    public AjaxResult isRegister(@RequestParam String phone)
    {
        String msg = registerService.isRegister(phone);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    @ApiOperation("发送验证码")
    @PostMapping("/sendSmsCode")
    @ApiImplicitParams({  @ApiImplicitParam(name = "phone",value = "手机号", required = true) ,
            @ApiImplicitParam(name = "type",value = "1 注册账号验证码 2 找回密码", required = false,defaultValue = "1")})
    public AjaxResult sendSmsCode(@RequestParam String phone ,@RequestParam Integer type)
    {
        registerService.sendSmsCode(phone,type);
        return AjaxResult.success();
    }

    @ApiOperation("找回密码")
    @PostMapping("/resetPassword")
    public AjaxResult resetPassword(@RequestBody  RegisterBody body)
    {
        registerService.resetPassword(body);
        return AjaxResult.success();
    }

}
